package api

import (
	"github.com/astaxie/beego"
	"os"
	"strconv"
)

type UploadController struct {
	base
}

func isDir(path string) bool {
	s, err := os.Stat(path)
	if err != nil {
		return false
	}
	return s.IsDir()
}

func (self *UploadController) domain() string {
	host := beego.AppConfig.String("host")
	port := self.Ctx.Input.Port()
	if port == 443 {
		return "https://" + host + "/"
	}
	if port == 80 {
		return "http://" + host + "/"
	}
	return "http://" + host + ":" + strconv.Itoa(port) + "/"
}
func (self *UploadController) UploadMdImage() {
	//d := time.Now()
	//year := strconv.Itoa(d.Year())
	//month := d.Format("01")

}

func (self *UploadController) UploadImageWithSign() {
	//self.uploadSuccess("")
	//day := strconv.Itoa(d.Day())
	//path := "static/upload/" + year + month + day
	//if !isDir(path) {
	//	err = os.MkdirAll(path, os.ModePerm)
	//	if err != nil {
	//		self.uploadError(err.Error())
	//	}
	//}
	//newFile := path + "/" + strconv.FormatInt(d.UnixNano(), 10) + ".jpeg"
	//if err := self.SaveToFile("editormd-image-file", newFile); err != nil {
	//	self.uploadError(err.Error())
	//}
	//self.uploadSuccess(self.domain() + newFile)
}
